<?php

class Sgit_Form_Filtros extends Zend_Form
{


    protected $decorator2 = array('ViewHelper', 
                                  'Errors', 
                                  array(
                                        array('data' => 'HtmlTag'), 
                                        array('tag' => 'div', 'class' => 'element')
                                  ), 
                                  array('Label', array('tag' => 'div')), 
                                  array(
                                            array('row' => 'HtmlTag'), 
                                            array('tag' => 'div', 'class' => 'padre')
                                  ),
    );
    
    protected $_orden=1;


    public function init()
    {

        

        $this->setMethod('post')->setAttrib('id', 'sgit_filtro');
        
        $request= Zend_Controller_Front::getInstance()->getRequest();
        
        $uri=$request->getPathInfo();
        
        $this->setAction($uri);



        $this->setDecorators(array("FormElements", 
                        array("HtmlTag", array("tag" => "div", "class" => 'sgit_filtro'))
                    , "Form"));


        
        
        $options = array('name' => 'buscar', 'label' => '', 'value' => 'on', 'id' => 'buscar', 'src' => '/img/viewmag.png');
        $image = new Zend_Form_Element_Image($options);
        
        
        
        
        
        
        $image->setOrder(100)
              ->setDecorators($this->decorator2);
        $this->addElement($image);


    }


    public function myRender()
    {
        $view = $this->getView();

        if ($this->count() == 1)
        {

            $view->filtros = '<div"></div>';
        }

        $view->filtros = $this->render().'<br><br>';
    }


    public function addInput($key, $label, $selected = null, $mas = array())
    {

        $element = new Zend_Form_Element_Text($key);
        $element->setLabel($label)
                ->setAttrib('size', 12)
                ->setDecorators($this->decorator2)
                ->addFilter('StringTrim')
                ->addFilter('Null')
                ->setOrder($this->_orden++);


        if (!is_null($selected))
        {
            $element->setValue($selected);
        }


        foreach ($mas as $k => $v)
        {
            $element->setAttrib($k, $v);
        }

        $this->addElement($element);
        return $this;
    }

    public function addFormSelect($select)
    {
        
        
        $select->setDecorators($this->decorator2)
               ->setOrder($this->_orden++)
               ->clearFilters();;
              
        $name= $select->getName();     
        
        $value= Zend_Controller_Front::getInstance()->getRequest()->getParam($name); 
        if($value) $select->setValue($value);       
        
          
               
        $this->addElement($select);
        return $this;
    }


    public function addPdf($bool = true)
    {
        if (!$bool)
            return $this;

        $options = array('name' => 'pdf', 'label' => '', 'value' => 'on', 'id' => 'pdf', 'src' => '/img/pdf.png');
        $image = new Zend_Form_Element_Image($options);
        
        $image->setDecorators($this->decorator2)
              ->setOrder(101);
        $this->addElement($image);


        return $this;
    }
    
   


    public function addExcel($bool = true)
    {
        if (!$bool)
            return $this;

        $options = array('name' => 'excel', 'label' => '', 'value' => 'on', 'id' => 'excel', 'src' => '/img/excel.gif');
        $image = new Zend_Form_Element_Image($options);

        $image->setDecorators($this->decorator2)
              ->setOrder(102);

        $this->addElement($image);

        return $this;
    }


}
